package c.h.a.w.k;

import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.util.Log;
import c.h.a.m0.j;
import c.h.a.m0.l;
import com.liuzh.deviceinfo.DeviceInfoApp;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* compiled from: AnalyzeRepeatFile */
public class e implements c.h.a.w.e.a {
    public Map<e, List<c.h.a.w.e>> a = new HashMap();
    public Map<String, List<c.h.a.w.e>> b = new HashMap();
    public List<b> c = new ArrayList();
    public List<f> d = new ArrayList();
    public boolean e = false;
    public boolean f = false;
    public long g = 0;
    public int h = 0;
    public ThreadLocal<d> i = new a(this);

    /* compiled from: AnalyzeRepeatFile */
    public class a extends ThreadLocal<d> {
        public a(e eVar) {
        }

        public Object initialValue() {
            return new d();
        }
    }

    /* compiled from: AnalyzeRepeatFile */
    public static class b {
        public static final String j = Environment.getExternalStoragePublicDirectory("android").getAbsolutePath();
        public static final String k = Environment.getExternalStoragePublicDirectory("dcim").getAbsolutePath();
        public static final String l = Environment.getExternalStoragePublicDirectory("pictures").getAbsolutePath();
        public static final String m = Environment.getExternalStoragePublicDirectory("download").getAbsolutePath();
        public static final String n = Environment.getExternalStoragePublicDirectory("downloads").getAbsolutePath();
        public static List<String> o;
        public final List<c.h.a.w.e> a;
        public final List<Boolean> b;
        public final c c;
        public final String d;
        public int e;
        public long f;
        public String g;
        public List<b> h;
        public SoftReference<Drawable> i;

        static {
            o = Arrays.asList(new String[]{r0, r1, r2, r3, r4});
        }

        public b(int i, List<c.h.a.w.e> list, List<Boolean> list2, c cVar, String str) {
            this.e = i;
            this.a = list;
            this.b = list2;
            this.c = cVar;
            this.d = str;
        }

        public int a() {
            return this.a.size();
        }

        public c.h.a.w.e b() {
            return (e() || this.e >= a()) ? null : (c.h.a.w.e) this.a.get(this.e);
        }

        public long c() {
            if (this.f == 0) {
                if (e()) {
                    for (c.h.a.w.e eVar : this.a) {
                        this.f += eVar.a;
                    }
                } else {
                    this.f = ((c.h.a.w.e) this.a.get(this.e)).a;
                }
            }
            return this.f;
        }

        public boolean d() {
            if (!e()) {
                return ((Boolean) this.b.get(this.e)).booleanValue();
            }
            for (Boolean booleanValue : this.b) {
                if (!booleanValue.booleanValue()) {
                    return false;
                }
            }
            return true;
        }

        public boolean e() {
            return this.e < 0;
        }

        public void f() {
            Object drawable;
            String d = j.d(((c.h.a.w.e) this.a.get(0)).e);
            DeviceInfoApp deviceInfoApp = DeviceInfoApp.c;
            b.f.a aVar = l.a;
            Object obj;
            if ("vnd.android.document/directory".equals(d)) {
                obj = b.i.c.a.a;
                drawable = deviceInfoApp.getDrawable(2131231008);
            } else {
                Integer num = (Integer) l.a.getOrDefault(d, null);
                if (num != null) {
                    int intValue = num.intValue();
                    try {
                        obj = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(intValue);
                    } catch (NotFoundException unused) {
                        drawable = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(2131231010);
                    }
                } else {
                    drawable = d.split("/")[0];
                    if ("audio".equals(drawable)) {
                        obj = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(2131231001);
                    } else if ("image".equals(drawable)) {
                        obj = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(2131231011);
                    } else if ("text".equals(drawable)) {
                        obj = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(2131231016);
                    } else if ("video".equals(drawable)) {
                        obj = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(2131231017);
                    } else {
                        drawable = b.i.c.a.a;
                        drawable = deviceInfoApp.getDrawable(2131231010);
                    }
                }
            }
            if (drawable != null) {
                this.i = new SoftReference(drawable);
            }
        }

        public void g() {
            this.f = 0;
            this.g = null;
            int i = 0;
            h(false);
            if (e() && this.c.a) {
                while (i < a()) {
                    List list = this.h;
                    if (list != null && i < list.size()) {
                        ((b) this.h.get(i)).e = i;
                    }
                    i++;
                }
            }
        }

        public void h(boolean z) {
            if (e()) {
                Collections.fill(this.b, Boolean.valueOf(z));
            } else {
                this.b.set(this.e, Boolean.valueOf(z));
            }
        }
    }

    /* compiled from: AnalyzeRepeatFile */
    public static class c {
        public boolean a = false;

        public c(a aVar) {
        }
    }

    /* compiled from: AnalyzeRepeatFile */
    public static class d {
        public byte[] a = new byte[1048576];
        public Map<String, List<c.h.a.w.e>> b = new HashMap();

        public d() {
            Log.d("AnalyzeRepeatFile", "Md5BufferWrapper: new obj");
        }
    }

    /* compiled from: AnalyzeRepeatFile */
    public static class e {
        public final String a;
        public final long b;

        public e(String str, long j) {
            this.b = j;
            int indexOf = str.indexOf(".");
            if (indexOf >= 0) {
                this.a = str.substring(indexOf);
            } else {
                this.a = "";
            }
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof e)) {
                return false;
            }
            e eVar = (e) obj;
            if (eVar.a.equals(this.a) && eVar.b == this.b) {
                return true;
            }
            return false;
        }

        public int hashCode() {
            return (this.a.hashCode() >> 24) ^ ((int) this.b);
        }
    }

    /* compiled from: AnalyzeRepeatFile */
    public interface f {
        void a(Map<String, List<c.h.a.w.e>> map, List<b> list);
    }

    public Map<String, List<c.h.a.w.e>> a(f fVar) {
        if (this.e) {
            return this.b;
        }
        if (fVar != null) {
            this.d.add(fVar);
        }
        return null;
    }

    public final <K, V> void b(K k, V v, Map<K, List<V>> map) {
        if (!this.f) {
            List list = (List) map.get(k);
            if (list == null) {
                list = new ArrayList();
            }
            list.add(v);
            map.put(k, list);
        }
    }

    public void f(long j, boolean z, c.h.a.w.e eVar) {
        this.g += j;
        this.h--;
        if (z) {
            eVar.i.remove(this);
        }
    }
}
